package com.zoke.moving.demo;

import android.animation.Animator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.RelativeLayout;

import com.zoke.moving.view.MovingImageView;

public class MainActivity extends AppCompatActivity {

    private MovingImageView moveIv;

    private RelativeLayout rootView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        moveIv = (MovingImageView) findViewById(R.id.moveIv);
        rootView = (RelativeLayout) findViewById(R.id.rootView);
        moveIv.setImageResource(R.mipmap.bg);
        moveIv.getMovingAnimator().addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                Log.i("MainActivity", "Start");
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                Log.i("MainActivity", "End");
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                Log.i("MainActivity", "Cancel");
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
                Log.i("MainActivity", "Repeat");
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        moveIv.getMovingAnimator().start();
    }

    @Override
    protected void onStop() {
        super.onStop();
        moveIv.getMovingAnimator().cancel();
    }
}
